package com.cat.slidingWindow;

import java.util.Arrays;

/**
 *   @description https://leetcode.cn/problems/minimum-removals-to-balance-array/description/
 *   @author 曲大人的喵
 *   @create 2025/9/17 11:38
 *   @since JDK17
 */

public class Solution35 {
    public int minRemoval(int[] nums, int k) {
        Arrays.sort(nums);  // 派升序
        int n = nums.length, ans = 0;
        for (int l = 0, r = 0; r < n; r++) {
            while ((long)nums[r] > (long)nums[l] * k) {
                l++;
            }
            ans = Math.max(ans, r - l + 1);
        }

        return n - ans;
    }
}
